#include <iostream>
using namespace std;

void print(int arr[], int len);
void insert_sort(int arr[], int len);
void insert_sort2(int arr[], int len);

int main()
{
    int arr[] = {9, 8, 7, 6, 5, 4, 3, 2, 1, 0};
    int len = sizeof(arr) / sizeof(int);

    print(arr, len);
    // insert_sort(arr, len);
    insert_sort2(arr, len);
    print(arr, len);

    return 0;
}

void print(int arr[], int len)
{
    for (int i = 0; i < len; ++i)
    {
        cout << arr[i] << " ";
    }
    cout << endl;
}

void insert_sort(int arr[], int len)
{
    int i = 0, j = 0;
    int cur = -1;
    for (i = 1; i < len; ++i)
    {
        cur = arr[i];
        for (j = i - 1; j >= 0 && cur < arr[j]; --j)
        {
            if (cur < arr[j])
            {
                arr[j + 1] = arr[j];
            }
            else
                break;
        }
        arr[j + 1] = cur;
    }
}

void insert_sort2(int arr[], int len)
{
    int i, j, cur;
    for (i = 1; i < len; ++i)
    {
        cur = arr[i];
        for (j = i - 1; j >= 0 && arr[j] > cur; j--)
        {
            if (arr[j] > cur)
            {
                arr[j + 1] = arr[j];
            }
        }
        arr[j + 1] = cur;
    }
}